/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pig.mt.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.pig4cloud.pig.mt.common.api.handler.JSONArrayTypeHandler;
import com.pig4cloud.pig.mt.common.api.handler.JSONObjectTypeHandler;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;

import java.util.Date;

/**
 * 消息模板
 *
 * @author JLM
 * @date 2021-03-05 11:45:09
 */
@Data
@TableName("wx_msg_template")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "消息模板")
public class WxMsgTemplate extends Model<WxMsgTemplate> {
private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @TableId(type = IdType.ASSIGN_UUID)
    @ApiModelProperty(value="id")
    private String id;
    /**
     * appid
     */
    @ApiModelProperty(value="appid")
    private String appid;
    /**
     * 公众号模板ID
     */
    @ApiModelProperty(value="公众号模板ID")
    private String templateId;
    /**
     * 模版名称
     */
    @ApiModelProperty(value="模版名称")
    private String name;
    /**
     * 标题
     */
    @ApiModelProperty(value="标题")
    private String title;
    /**
     * 模板内容
     */
    @ApiModelProperty(value="模板内容")
    private String content;
    /**
     * 消息内容
     */
    @ApiModelProperty(value="消息内容")
	@TableField(typeHandler = JSONArrayTypeHandler.class)
	private JSONArray data;
    /**
     * 链接
     */
    @ApiModelProperty(value="链接")
    private String url;
    /**
     * 小程序信息
     */
    @ApiModelProperty(value="小程序信息")
	@TableField(typeHandler = JSONObjectTypeHandler.class)
	private JSONObject miniprogram;
    /**
     * 是否有效
     */
    @ApiModelProperty(value="是否有效")
    private Boolean status;
    /**
     * 修改时间
     */
    @ApiModelProperty(value="修改时间")
    private Date updateTime;

	public WxMsgTemplate() {

	}

	public WxMsgTemplate(WxMpTemplate mpTemplate, String appid) {
		this.appid = appid;
		this.templateId = mpTemplate.getTemplateId();
		this.title = mpTemplate.getTitle();
		this.name = mpTemplate.getTemplateId();
		this.content = mpTemplate.getContent();
		this.status = true;
	}
}
